# Build stage
FROM golang:1.23-alpine AS builder

WORKDIR /build

# Copy go.work and all go.mod files
COPY go.work ./
COPY proto/go.mod proto/go.sum ./proto/
COPY shared/go.mod shared/go.sum ./shared/
COPY services/ai-gateway/go.mod services/ai-gateway/go.sum ./services/ai-gateway/
COPY services/alert-service/go.mod services/alert-service/go.sum ./services/alert-service/
COPY services/api-gateway/go.mod services/api-gateway/go.sum ./services/api-gateway/
COPY services/integration-service/go.mod services/integration-service/go.sum ./services/integration-service/
COPY services/notification-service/go.mod services/notification-service/go.sum ./services/notification-service/
COPY services/ticket-service/go.mod services/ticket-service/go.sum ./services/ticket-service/
COPY services/user-service/go.mod services/user-service/go.sum ./services/user-service/
COPY services/workflow-service/go.mod services/workflow-service/go.sum ./services/workflow-service/

# Download dependencies
RUN go mod download

# Copy source code (including generated proto files)
COPY proto/gen ./proto/gen
COPY proto/go.mod proto/go.sum ./proto/
COPY shared ./shared
COPY services/integration-service ./services/integration-service

# Build
WORKDIR /build/services/integration-service
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o integration-service ./cmd

# Final stage
FROM alpine:latest

RUN apk --no-cache add ca-certificates

WORKDIR /app

COPY --from=builder /build/services/integration-service/integration-service .

EXPOSE 50056

CMD ["./integration-service"]
